#ifndef MATRIXSTACK_H
#define MATRIXSTACK_H

#include <deque>
#include "Matrix.h"

class MyGLWidget;
class MainWindow;

class MatrixStack
{
public:
	MatrixStack(MyGLWidget &glWidget, MainWindow &mainWindow);
	
	void applyStack();
	void popStack();
	
	/// returns matrix id
	int pushMatrix(const Matrix &mtx);

	int pushMatrix();

	Matrix &getMatrix(int id);

	void updateResultMtx();

	// returns true if moved successfully
	bool moveMatrixUp(int id);
	bool moveMatrixDown(int id);

private:
	
	struct MatrixRecord
	{
		int id;
		Matrix mtx;

		MatrixRecord(int id, const Matrix &mtx): id(id), mtx(mtx) {}
		explicit MatrixRecord(int id): id(id) { mtx.identity(); }
	};

	typedef std::deque<MatrixRecord> MatrixList;

	MatrixList::iterator findMatrix(int id);
	
	Matrix m_resultMtx;
	
	MatrixList m_list;

	MyGLWidget &m_glWidget;

	MainWindow &m_mainWindow;
};

#endif // MATRIXSTACK_H
